package com.ruoyi.test.web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.test.domain.People;
import com.ruoyi.test.serv.IPeopleServ;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员信息Controller
 *
 * @author ruoyi
 * @date 2024-05-04
 */
@RestController
@RequestMapping("/test/people")
public class PeopleController extends BaseController {
    @Autowired
    private IPeopleServ serv;

    /**
     * 查询人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('test:people:list')")
    @GetMapping("/list")
    public TableDataInfo list(People vo) {
        System.out.println(new Throwable().getStackTrace()[0]);
        startPage();
        List<People> list = serv.list(vo);
        return getDataTable(list);
    }

    /**
     * 导出人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('test:people:export')")
    @Log(title = "人员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, People vo) {
        System.out.println(new Throwable().getStackTrace()[0]);
        List<People> list = serv.list(vo);
        ExcelUtil<People> util = new ExcelUtil<People>(People.class);
        util.exportExcel(response, list, "人员信息数据");
    }

    /**
     * 获取人员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('test:people:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getOne(@PathVariable("id") String id) {
        System.out.println(new Throwable().getStackTrace()[0]);
        return success(serv.getOne(id));
    }

    /**
     * 新增人员信息
     */
    @PreAuthorize("@ss.hasPermi('test:people:add')")
    @Log(title = "人员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody People vo) {
        System.out.println(new Throwable().getStackTrace()[0]);
        return toAjax(serv.add(vo));
    }

    /**
     * 修改人员信息
     */
    @PreAuthorize("@ss.hasPermi('test:people:edit')")
    @Log(title = "人员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody People vo) {
        System.out.println(new Throwable().getStackTrace()[0]);
        return toAjax(serv.update(vo));
    }

    /**
     * 删除人员信息
     */
    @PreAuthorize("@ss.hasPermi('test:people:remove')")
    @Log(title = "人员信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        System.out.println(new Throwable().getStackTrace()[0]);
        return toAjax(serv.deleteByIds(ids));
    }
}
